package demo13StringBuffer和StringBulider;

/**
 * StringBuffer和StringBuilder的使用
 * 和String区别
 * （1）效率比String高
 * （2）比String节省内存
 * @author gjw
 */
public class Demo06 {
    public static void main(String[] args) {
        StringBuffer stringBuffer = new StringBuffer();
        //1 append();追加
        stringBuffer.append("java世界第一");
        System.out.println(stringBuffer.toString());
        stringBuffer.append("java真香");
        System.out.println(stringBuffer.toString());
        stringBuffer.append("java 不错");
        System.out.println(stringBuffer.toString());
        //2.insert();添加
        stringBuffer.insert(0, "我在最前面");
        System.out.println(stringBuffer.toString());
        //3.replace();替换 含头不含尾
        stringBuffer.replace(0, 5, "hello");
        System.out.println(stringBuffer.toString());
        //4.delete();删除 含头不含尾
        stringBuffer.delete(0, 5);
        System.out.println(stringBuffer.toString());
        //清空
        stringBuffer.delete(0, stringBuffer.length());
        System.out.println(stringBuffer.length());
    }
}
